package cn.jdx.tools.zip;

import java.io.File;
import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
import net.lingala.zip4j.model.ZipParameters;
import net.lingala.zip4j.util.Zip4jConstants;


public class 测试压缩文件夹 {

    private static void zipFile(String inputPath,String outputPath) throws ZipException {
        ZipParameters parameters = new ZipParameters();
        // 压缩方式
        parameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
        // 压缩级别
        parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
        // 要打包的文件夹
        File currentFile = new File(inputPath);
        // 生成的压缩文件
        ZipFile zipFile = new ZipFile(outputPath);
        // 遍历test文件夹下所有的文件、文件夹
        File[] fs = currentFile.listFiles();
        for (File f : fs) {
            if (f.isDirectory()) {
                zipFile.addFolder(f.getPath(), parameters);
            } else {
                zipFile.addFile(f, parameters);
            }
        }
    }

    public static void main(String[] args) throws ZipException {
        String inputPath = "C:\\Users\\PL\\Desktop\\zip4j";
        String outputPath = "C:\\Users\\PL\\Desktop\\temp.zip";
        zipFile(inputPath,outputPath);
    }
}
